#!/usr/bin/env python
# -*- coding:utf-8 -*-

from flask_restful import Resource, reqparse
from utils import commons
from flask import jsonify
from service.todolistService import TodolistService


class TodolistOtherResource(Resource):
	# add
	@classmethod
	def add_list(cls):
		parser = reqparse.RequestParser()
		parser.add_argument('Title', location='form', required=False, help='Title参数类型不正确或缺失')
		parser.add_argument('UserID', location='form', required=False, help='UserID参数类型不正确或缺失')

		kwargs = parser.parse_args()
		kwargs = commons.put_remove_none(**kwargs)

		res = TodolistService.add_list(**kwargs)

		return jsonify(code=res['code'], message=res['message'], data=res['data'])

	# 模糊查询
	@classmethod
	def fuzzy_query(cls):
		parser = reqparse.RequestParser()
		parser.add_argument('Title', location='args', required=False, help='Title参数类型不正确或缺失')
		parser.add_argument('UserID', location='args', required=False, help='UserID参数类型不正确或缺失')

		kwargs = parser.parse_args()
		kwargs = commons.put_remove_none(**kwargs)

		res = TodolistService.fuzzy_query(**kwargs)

		return jsonify(code=res['code'], message=res['message'], data=res['data'])
